import React, { Component } from 'react'
// import Pubsub from 'pubsub-js'
import './Footer.css'
export default class Footer extends Component {
  // 清除所有完成任务的事件处理函数
  clearAllDone = () => {
    // 通知app删除调所有已完成任务
    this.props.clear()
  }
  render() {
    // 动态计算任务的总数和已完成任务数
    const { todos } = this.props
    const allTotal = todos.length
    const doneTotal = todos.filter((item) => item.isDone).length

    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={doneTotal === allTotal}
            onChange={(e) => {
              // 获取目标值
              const target = e.target.checked
              this.props.updateAllTodo(target)
            }}
          />
        </label>
        <span>
          <span>已完成 {doneTotal}</span> / 全部 {allTotal}
        </span>
        <button className="btn btn-danger" onClick={this.clearAllDone}>
          清除已完成任务
        </button>
      </div>
    )
  }
}
